<script src="/js/validateIsMain.js"></script>
<div id="subContainer">
    <header class="page-header no-margin">
        <div class="container-fluid">
            <h2 class="no-margin-bottom" style="margin-top: 0px; font-size: 20px;">GIT</h2>
        </div>
    </header>

    <div class="breadcrumb-holder container-fluid">
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.html">首页</a></li>
            <li class="breadcrumb-item active">GIT</li>
        </ul>
    </div>

    <section class="tables">
        <div class="container-fluid">
            <div class="row">
                <div class="card">
                    <div class="card-header d-flex align-items-center">
                        <h3 class="h4">仓库列表</h3>
                    </div>
                    <div class="card-body" style="padding-top: 0px;">
                        <form class="form-inline" action="#">
                            <div class="form-group">
                                <select class="form-control mr-3" v-model="pageInfo.isAll">
                                    <option value="true" selected>全部</option>
                                    <option value="false">运行中</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <input type="text" placeholder="请输入容器名称" class="form-control mr-3"
                                       v-model="pageInfo.name">
                            </div>
                            <div class="form-group">
                                <input type="text" placeholder="xxx" class="form-control mr-3">
                            </div>
                            <div class="form-group">
                                <button type="button" class="btn btn-success" @click="pagequery()"><i
                                        class="fa fa-search"></i>查询
                                </button>
                                <button type="button" class="btn btn-primary" @click="add()"><i
                                        class="fa fa-search"></i>新建
                                </button>
                            </div>
                        </form>

                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                <th>序号</th>
                                <th>名称</th>
                                <th>备注</th>
                                <th>地址</th>
                                <th>用户名</th>
                                <th>密码</th>
                                <th>操作</th>
                                </thead>
                                <tbody>
                                <tr v-for="(item, index) in items">
                                    <th scope="row">{{(pageInfo.pageNum - 1) * 10 + index + 1}}</th>
                                    <td><span style="cursor: help;">{{item.name}}</span></td>
                                    <td><span style="cursor: help;">{{item.remark}}</span></td>
                                    <td><span style="cursor: help;">{{item.addr}}</span></td>
                                    <td><span style="cursor: help;">{{item.authUser}}</span></td>
                                    <td><span style="cursor: help;">****</span></td>
                                    <td>
                                        <a class="btn btn-xs btn-info" @click="details(item)"
                                           style="font-size: 0.7rem; padding: 0.2rem; color: white;"><i
                                                class="fa fa-edit"></i>编辑</a>
                                        <a class="btn btn-xs btn-danger" @click="deleteItem(item)"
                                           style="font-size: 0.7rem; padding: 0.2rem; color: white;"><i
                                                class="fa fa-trash"></i>删除</a>
                                        <a class="btn btn-xs btn-success" @click="setDeploy(item)"
                                           style="font-size: 0.7rem; padding: 0.2rem; color: white;"><i
                                                class="fa fa-product-hunt"></i>设置项目</a>
                                    </td>
                                </tr>
                                </tbody>
                            </table>

                            <div class="pageination">
                                <pageination :total="pageInfo.total" :size="pageInfo.size" :page="pageInfo.pageNum"
                                             :changge="pageFn"></pageination>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <footer class="main-footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <p>Copyright &copy; 2019.Company name All rights reserved.More Templates <a
                            href="http://www.jq22.com/" target="_blank" title="jq22">jq22</a></p>
                </div>
                <div class="col-sm-6 text-right">
                    <p></p>
                </div>
            </div>
        </div>
    </footer>
</div>

<script>
    indexPage = new Vue({
        el: '#subContainer',
        data: {
            applicationContextRootPath: '/survey/',
            pageInfo: {
                pageNum: 1,
                total: 100,//总页数
                size: 10,//每页显示条目个数不传默认10
                isAll: true,
                name: '',
                image: ''
            },
            items: []
        },
        created: function () {
        },
        methods: {
            setDeploy(item) {
                // 设置部署属性
                toPage('/pages/repository/addContainer.html', JSON.stringify(item));
            },
            deleteItem(item) {
                let that = this;
                confirm("您确定要删除这个仓库吗?", "", function (isConfirm) {
                    if (isConfirm) {
                        AJAX.DELETE("/repository/" + item.id, {}, function (resp) {
                            toastr.success(resp.msg);
                            that.pagequery();
                        })
                    }
                }, {confirmButtonText: '确认', cancelButtonText: '取消', width: 400});

            },
            add() {
                toPage('/pages/repository/add.html');
            },
            details(item) {
                toPage('/pages/repository/edit.html', item.id);
            },
            pagequery: function () {
                var that = this;
                AJAX.GET('/repository', this.pageInfo, function (resp) {
                    that.items = resp.data.list;
                    that.pageInfo.pageNum = resp.data.pageNum;
                    that.pageInfo.total = resp.data.total;
                })
            },
            pageFn: function (val) {
                this.pageInfo.pageNum = val;
                this.pagequery();
            },
            textFilter(text, num) {
                num = num ? num : 12;
                if (text.length > num) {
                    return text.substr(0, num) + '...';
                }
                return text
            },
            nameFilter(text) {
                if (text) {
                    return text.substr(1, text.length);
                }
                return text;
            }
        }
    });
</script>